<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>系统配置</title>
    <link rel="icon" th:href="@{/img/icon.ico}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;padding-right: 10px;line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" action="" lay-filter="formDemo">
            <div class="layui-form layuimini-form">
                <input type="hidden" name="id" th:value="${data.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">网站标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="websiteTitle" placeholder="请输入" class="layui-input" th:value="${data.websiteTitle}">
                        <tip>浏览器tab栏的标题，关键词放最前面，网站名称放后面，用英文“-”隔开</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站图标</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="websiteIcon" th:value="${data.websiteIcon}">
                        <div style="height: 100px;width: 100px;position: relative;">
                            <input type="file" accept="image/*" id="pic-input1" style="position: absolute;left: 0;top: 0;opacity: 0;filter: alpha(opacity=0);height: 100%;width: 100%;z-index: 99">
                            <img th:src="${data.websiteIcon}" alt="" id="pic-img1" style="height: 100%;width: 100%;position: absolute;left: 0;top: 0;border: 1px solid #1E9FFF;">
                        </div>
                        <tip>浏览器tab栏的图标，一般为.ico文件</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">META关键字</label>
                    <div class="layui-input-block">
                        <input type="text" name="websiteKeywords" placeholder="请输入" class="layui-input" th:value="${data.websiteKeywords}">
                        <tip>搜索引擎用于排名，重要的放在前面，用英文“,”隔开</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">META描述</label>
                    <div class="layui-input-block">
                        <input type="text" name="websiteDescription" placeholder="请输入" class="layui-input" th:value="${data.websiteDescription}">
                        <tip>网页的简要内容概况，应为完整的一句话</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站备案号</label>
                    <div class="layui-input-block">
                        <input type="text" name="recordNo" placeholder="请输入" class="layui-input" th:value="${data.recordNo}">
                        <tip>网站备案管理系统颁发的网络信息许可证号码</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">版权信息</label>
                    <div class="layui-input-block">
                        <input type="text" name="copyright" placeholder="请输入" class="layui-input" th:value="${data.copyright}">
                        <tip>网站的版权信息，一般放于网页底部，例：Copyright© 2020 XXX版权所有</tip>
                    </div>
                </div>
                <hr style="background-color: #1890ff">
                <div class="layui-form-item">
                    <label class="layui-form-label">系统名称(简称)</label>
                    <div class="layui-input-block">
                        <input type="text" name="systemName" placeholder="请输入" maxlength="10" class="layui-input" th:value="${data.systemName}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">系统名称(全称)</label>
                    <div class="layui-input-block">
                        <input type="text" name="systemFullName" placeholder="请输入" class="layui-input" th:value="${data.systemFullName}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">系统LOGO</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="systemLogo" th:value="${data.systemLogo}">
                        <div style="height: 100px;width: 100px;position: relative;">
                            <input type="file" accept="image/*" id="pic-input" style="position: absolute;left: 0;top: 0;opacity: 0;filter: alpha(opacity=0);height: 100%;width: 100%;z-index: 99">
                            <img th:src="${data.systemLogo}" alt="" id="pic-img" style="height: 100%;width: 100%;position: absolute;left: 0;top: 0;border: 1px solid #1E9FFF;">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="saveBtn" shiro:hasPermission="sys:configure:edit"> 保存 </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>

<script type="text/javascript" th:inline="javascript">

    layui.use(['form','notice'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            notice = layui.notice;

        var ctxPath = /*[[@{/}]]*/;
        var baseUrl = ctxPath + 'sys/sys-configure/';

        $('#pic-input').change(function () {
            var formData = new FormData();
            formData.append("files", $("#pic-input")[0].files[0]);
            var index = layer.load();
            $.ajax({
                type : "POST",
                cache: false,
                dataType: "json",
                data : formData,
                headers:{'Minio-dir': 'sys_configure'},
                processData :  false,
                contentType :  false,
                url: ctxPath + 'sys/sys-minio/uploadFileAjax',
                success:function(res){
                    layer.close(index);
                    if(200 == res.code){
                        $("input[name='systemLogo']").val(res.data);
                        $('#pic-img').attr('src',res.data);
                        notice.success('上传成功');
                    }else{
                        notice.warning('上传失败');
                    }
                },
                error:function() {
                    layer.close(index);
                    notice.error("服务器异常！");
                }
            });
        });

        $('#pic-input1').change(function () {
            var formData = new FormData();
            formData.append("files", $("#pic-input1")[0].files[0]);
            var index = layer.load();
            $.ajax({
                type : "POST",
                cache: false,
                dataType: "json",
                data : formData,
                headers:{'Minio-dir': 'sys_configure'},
                processData :  false,
                contentType :  false,
                url: ctxPath + 'sys/sys-minio/uploadFileAjax',
                success:function(res){
                    layer.close(index);
                    if(200 == res.code){
                        $("input[name='websiteIcon']").val(res.data);
                        $('#pic-img1').attr('src',res.data);
                        notice.success('上传成功');
                    }else{
                        notice.warning('上传失败');
                    }
                },
                error:function() {
                    layer.close(index);
                    notice.error("服务器异常！");
                }
            });
        });

        // 监听提交
        form.on('submit(saveBtn)', function (res) {
            var data = res.field;
            var index = layer.load();
            $.ajax({
                url: baseUrl + 'update',
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(data),
                contentType:"application/json",
                success: function (res) {
                    layer.close(index);
                    if (200 == res.code) {
                        notice.success(res.msg);
                        setTimeout(function () {
                            window.location.reload();
                        },1500)
                    }
                    else {
                        notice.warning(res.msg);
                    }
                },
                error: function (res) {
                    layer.close(index);
                    notice.error("服务器异常！");
                }
            });
            return false;
        });
    });
</script>
</body>
</html>